import { IRequestConfig, IResponse, IResolve, InterceptorsConfig, IApiControl, IRequestHook } from '../BaseInterface'

/**
 * 全局默认请求拦截器
 */
const interceptors: InterceptorsConfig = {
    request: function (options: IRequestConfig, apiControl: IApiControl): IRequestHook {
        return { type: true, message: 'ok' }
    },
    response: function (response: IResponse, options: IRequestConfig, apiControl: IApiControl): Promise<any> | IResolve {
        // 简单判断下返回状态然后返回 - 需要不同的处理需传入自定义返回拦截操作
        const res = response.data
        if (response.status === 200) {
            return { data: res }
        } else {
            return Promise.reject(res)
        }
    }
}

export default interceptors